﻿function DeleteDialog() {
    var mainWindow;
    var curUserId;
    var userGrid;
    return {
        init: function (userTable) {
            userGrid = userTable;
            mainWindow = $('#windowDelete').jqxWindow({
                resizable: false, autoOpen: false,
                height: 110, width: 200,
                theme: theme, isModal: true,
                cancelButton: $('.deleteCloseButtom'),
                initContent: function () {
                    $(".deleteCloseButtom").jqxButton({ width: '80', theme: theme });
                    $('#deleteOk').bind('click', function () {
                        $.ajax({
                            url: '/data/user?login=' + curUserId,
                            //data: JSON.stringify({ login: curUserId }),
                            type: "DELETE",
                            contentType: 'application/json; charset=utf-8'
                        }).done(function (data) {
                            if (data!=null&&data != '') {
                                alert(data.toString(), "Внимание");
                            } else {
                                userGrid.DeleteRow(curUserId);
                            }
                        }).error(function () {
                            alert('Проверьте подключение к интернету и обновите окно.', "Ошибка связи");
                        });
                    });
                }
            });
        },
        openDialog: function (data) {
            curUserId = data;
            $('#deleteUserLogin').text(curUserId);
            mainWindow.jqxWindow('open');
        }
    };
};